package com.sitanyun.merchant.guide.model.impl;

import com.google.gson.Gson;
import com.sitanyun.merchant.guide.bean.LoginBean;
import com.sitanyun.merchant.guide.bean.SmsPhoneBean;
import com.sitanyun.merchant.guide.callback.StringCallbacks;
import com.sitanyun.merchant.guide.model.inter.ISmsLoginAModel;
import com.sitanyun.merchant.guide.presenter.callback.CallBack;
import com.sitanyun.merchant.guide.url.Urls;
import com.zhy.http.okhttp.OkHttpUtils;

import okhttp3.Call;

public class SmsLoginAModelImpl implements ISmsLoginAModel {
    @Override
    public <T> void setsmslogin(String mobile, String type, CallBack callBack) {
        OkHttpUtils.get().url(Urls.getsms+"/"+mobile+"/"+type)
                .addHeader("Content-Type","application/json")
                .build().execute(new StringCallbacks() {
            @Override
            public void onError(Call call, Exception e, int id) {

            }

            @Override
            public void onResponse(String response, int id) {
                SmsPhoneBean smsPhoneBean  = new Gson().fromJson(response, SmsPhoneBean.class);
               callBack.onSuccess(smsPhoneBean);
            }
        });
    }

    @Override
    public <T> void setLoginpass(String phone, String password, CallBack callBack) {
        String urls=Urls.Login+"?phone="+phone+"&verifycode="+password+"&grant_type=verifycode"+"&scope=server&s_client_id=MERCHANT"+"&privilege=GUIDE";
        OkHttpUtils.post().url(urls)
                .addHeader("Authorization","Basic dGVzdDp0ZXN0")
                .build().execute(new StringCallbacks() {
            @Override
            public void onError(Call call, Exception e, int id) {

            }

            @Override
            public void onResponse(String response, int id) {
                LoginBean loginBean  = new Gson().fromJson(response, LoginBean.class);
                callBack.onSuccess(loginBean);
            }
        });
    }
}
